package qc.common.core.utils;

import qc.common.core.enums.FileTypeEnum;

/**
 * 文件类型工具
 *
 * @author QuCheng Tech
 * @since 2023/6/8
 */
public class FileTypeUtil {
    /**
     * 根据文件扩展名得到文件类型枚举
     *
     * @param fileExtension 文件扩展名
     * @return 文件类型枚举
     * @author QuCheng Tech
     * @since 2023/6/8
     */
    public static FileTypeEnum getByExtension(String fileExtension) {
        switch (fileExtension.toLowerCase()) {
            case "txt":
                return FileTypeEnum.TEXT;
            case "doc":
            case "docx":
                return FileTypeEnum.WORD;
            case "xls":
            case "xlsx":
                return FileTypeEnum.EXCEL;
            case "pdf":
                return FileTypeEnum.PDF;
            case "xml":
            case "htm":
            case "html":
            case "md":
                return FileTypeEnum.MARK;
            case "rtf":
            case "ppt":
            case "pptx":
                return FileTypeEnum.DOCUMENT;
            case "jpg":
            case "jpeg":
            case "png":
            case "gif":
                return FileTypeEnum.IMAGE;
            case "mp3":
            case "wav":
                return FileTypeEnum.AUDIO;
            case "mp4":
            case "mov":
            case "rmvb":
                return FileTypeEnum.VIDEO;
            case "exe":
            case "jar":
            case "war":
                return FileTypeEnum.EXE;
            case "zip":
            case "rar":
                return FileTypeEnum.ZIP;
            default:
                return FileTypeEnum.UN_KNOW;
        }
    }
}
